//
//  YZIMAssitantVC.m
//  VET
//
//  Created by YZ on 2018/7/11.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZIMAssitantVC.h"
#import "YZIMAssitantViewModel.h"
#import "YZIMAssitantWelcomeCell.h"
#import "YZIMAssitantContentCell.h"

@interface YZIMAssitantVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *contentTb;

@property (nonatomic, strong) YZIMAssitantViewModel *viewModel;

@end

@implementation YZIMAssitantVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configUI];
    [self initUI];
}

- (void)configUI
{
    self.view.backgroundColor = kColorWithHex(0xE9EAEB);
    self.title = @"小影";
}

- (void)initUI
{
    [self.view addSubview:self.contentTb];
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.viewModel.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.viewModel.dataSource[section].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    if(indexPath.row == 0)
    {
        static NSString *cellId = @"YZIMAssitantWelcomeCell";
        cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if(!cell){
            cell = [[YZIMAssitantWelcomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }
        ((YZIMAssitantWelcomeCell *)cell).model = [self.viewModel modelInSection:indexPath.section row:indexPath.row];
    }else
    {
        static NSString *cellId = @"YZIMAssitantContentCell";
        cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if(!cell){
            cell = [[YZIMAssitantContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            ((YZIMAssitantContentCell *)cell).model = [self.viewModel modelInSection:indexPath.section row:indexPath.row];
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}


#pragma mark -- setters && getters

- (UITableView *)contentTb
{
    if(!_contentTb){
        _contentTb = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - (kStatusBarHeight + YZ_BOTTOM_MARGIN)) style:UITableViewStylePlain];
        _contentTb.backgroundColor = [UIColor clearColor];
        _contentTb.separatorStyle = UITableViewCellSeparatorStyleNone;
        _contentTb.tableFooterView = [UIView new];
        _contentTb.delegate = self;
        _contentTb.dataSource = self;
        _contentTb.estimatedRowHeight = kCurrentDeviceNum(44);
    }
    return _contentTb;
}

- (YZIMAssitantViewModel *)viewModel
{
    if(!_viewModel){
        _viewModel = [YZIMAssitantViewModel new];
    }
    return _viewModel;
}
@end
